package com.deyuanyun.pic.pipe.service.impl;

import com.deyuanyun.pic.common.dto.BasicDataByFind;
import com.deyuanyun.pic.common.dto.DTOResult;
import com.deyuanyun.pic.common.exception.ExceptionCode;
import com.deyuanyun.pic.common.exception.PicException;
import com.deyuanyun.pic.common.util.ObjectUtil;
import com.deyuanyun.pic.pipe.mapper.dao.PiggingStructureDao;
import com.deyuanyun.pic.pipe.service.PipeBaseInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PipeBaseInfoServiceImpl implements PipeBaseInfoService {
	@Resource
	private PiggingStructureDao piggingStructureDao;

	@Override
	public DTOResult getPipeBaseInfo() {
		List list = null ;
		try {
			list = piggingStructureDao.searchPipeBaseInfo();
		} catch (PicException e) {
			e.printStackTrace();
		}
		return new DTOResult(ExceptionCode.SUCCESS.getCode(), ExceptionCode.SUCCESS.getLabel(), list);
	}
	
	@Override
	public DTOResult searchPipeBaseInfo(BasicDataByFind bData) {
		List list = null;
		try {
			if(ObjectUtil.isEmptyAll(bData.getLineId()) && ObjectUtil.isEmptyAll(bData.getSegmentId())){
				//如果没有选择任何查询条件
				list = piggingStructureDao.searchPipeBaseInfo();
			}
			else if(!ObjectUtil.isEmptyAll(bData.getLineId()) && ObjectUtil.isEmptyAll(bData.getSegmentId())){
				//如果选择了管道，没有选择管段 以管道为条件
				list = piggingStructureDao.searchPipeBaseInfoByLine(bData.getLineId());
			}else if(!ObjectUtil.isEmptyAll(bData.getLineId()) && !ObjectUtil.isEmptyAll(bData.getSegmentId())){
				//如果选择了管道和管段  已管段为条件
				list = piggingStructureDao.searchPipeBaseInfoBySegment(bData.getSegmentId());
			}
		} catch (PicException e) {
			e.printStackTrace();
		}
		return new DTOResult(ExceptionCode.SUCCESS.getCode(), ExceptionCode.SUCCESS.getLabel(), list);
	}

	
	
}
